#include "ScnsPmw3901.c.h"

#if defined(SCNS_PMW3901_ENABLE)&&SCNS_PMW3901_ENABLE==1

#include "ScnsMenu.h"
#include "ScnsSmctpExtOscilloscope.h"

ScnsStatus scnsBspPmw3901Init(ScnsPmw3901Enum pmwN)
{
    spi_init(SPI_2,SPI_MODE3,system_clock/24,SPI2_SCK_B13,SPI2_MOSI_B15,SPI2_MISO_B14,SPI2_CS_B12);
    return SCNS_STATUS_OK;
}

ScnsStatus scnsBspPmw3901PostInit(ScnsPmw3901Enum pmwN)
{
    scnsMenuSetPage(6,"Pmw3901",NULL);
    scnsMenuAddConstStruct(6,scnsPmw3901Result[pmwN],x,,SCNS_TYPE_FLOAT);
    scnsMenuAddConstStruct(6,scnsPmw3901Result[pmwN],y,,SCNS_TYPE_FLOAT);
    scnsMenuAddConstStruct(6,scnsPmw3901Result[pmwN],sumX,,SCNS_TYPE_FLOAT);
    scnsMenuAddConstStruct(6,scnsPmw3901Result[pmwN],sumY,,SCNS_TYPE_FLOAT);
    
    return SCNS_STATUS_OK;
}

void scnsBspPmw3901RW(ScnsPmw3901Enum pmwN,uint8*val,uint32 num)
{
    spi_transfer_8bit(SPI_2,val,val,num);
}

float scnsBspPmwGetHeight(ScnsPmw3901Enum pmwN)
{
    return 0.145;
}

void scnsBspPmw3901ResultUpdate(ScnsPmw3901Enum pmwN)
{
    if(scnsMenuCanPageSend(6))
    {
        scnsSmctpExtOscilloscopeSend(SCNS_SMCTP_CHANNEL_VISUAL_SCOPE,SCNS_SMCTP_CHANNEL_VISUAL_SCOPE,
            scnsPmw3901Result[pmwN].x,
            scnsPmw3901Result[pmwN].y,
            scnsPmw3901Result[pmwN].sumX,
            scnsPmw3901Result[pmwN].sumY,
        );
    }
}

#endif
